#!/bin/bash

# 关闭 selinux 防火墙，禁用 swap

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0

systemctl disable --now firewalld.service
systemctl disable --now NetworkManager
systemctl disable --now dnsmasq

swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab


# 安装依赖包，更新已安装的应用

yum install -y epel-release
yum install -y vim wget jq psmisc socat yum-utils device-mapper-persistent-data lvm2 ipvsadm ipset sysstat conntrack libseccomp
yum update -y --exclude=kernel*


# 升级内核版本

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
if [[ ! 0 -eq `echo $?` ]]; then
    exit 1
fi
grub2-set-default 0 && grub2-mkconfig -o /etc/grub2.cfg

# 修改 hostname
hostnamectl set-hostname $1

# 添加主机名 host 映射

echo "$2 $1" >> /etc/hosts
